package com.chenjun.web.controller.oa;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chenjun.common.Constant;
import com.chenjun.common.base.ResultDto;
import com.chenjun.common.bean.Pagination;
import com.chenjun.common.model.DataGridModel;
import com.chenjun.common.model.DataGridSortModel;
import com.chenjun.core.dao.generator.entity.OaBillAttnDayReport;
import com.chenjun.core.service.oa.OaBillAttnDayReportService;
import com.chenjun.web.controller.BaseController;

/**
 * @Description: 非标准工时修正
 * @author dongyibin
 * @date 2017-8-9 下午8:44:40
 */
@SuppressWarnings("serial")
@Controller
@RequestMapping("nonstandardHours")
public class NonstandardHoursController extends BaseController {

	@Autowired
	OaBillAttnDayReportService dayReportService;

	/**
	 * @Description: 进入非标准工时修正页面
	 * @return
	 * @author dongyibin
	 * @date 2017-8-9 下午8:57:15
	 */
	@RequestMapping("/list.html")
	public String index() {
		return "exceptionAttendance/nonstandardHours";
	}

	/**
	 * @Description: 获取人员非标准工时制信息
	 * @param model
	 * @return
	 * @author dongyibin
	 * @date 2017-9-11 下午11:16:36
	 */
	@RequestMapping("/search")
	@ResponseBody
	public ResultDto getNonstandardHours(DataGridModel model) {
		ResultDto rtDto = new ResultDto();
		String ids= model.getParams().get("userIds").toString();
		model.getParams().put("userIds", Arrays.asList(ids.split(","))); 
		model.getParams().put("nhoursTypeId", Constant.STANDARD_HOURS_TYPE); // 工时制ID
		model.getSortBy().add(new DataGridSortModel("bill_date", DataGridSortModel.ASC));
		Pagination data = dayReportService.doPagination(model);
		rtDto.setData(data);
		return rtDto;
	}
	
	/**
	 * 
	 * @Description: 修改不定时工时制人员工时
	 * @param request
	 * @param oaBillAttnDayReport
	 * @return
	 * @author dongyibin
	 * @date 2017-8-16 上午12:12:25
	 */
	@RequestMapping("/edit")
	@ResponseBody
	public ResultDto updateUserHours(HttpServletRequest request, OaBillAttnDayReport oaBillAttnDayReport){
		ResultDto rtDto = new ResultDto();
		oaBillAttnDayReport.setChangeNormalHours(oaBillAttnDayReport.getNormalHours()); // 更新修正后的小时数
		int rows = dayReportService.createOrUpdate(oaBillAttnDayReport);
		if(rows <= 0) {
			rtDto.resultError();
			rtDto.setMessage("编辑系统异常");
		}
		return rtDto;
	}
	
	/**
	 * @Description: 根据参数获取信息 
	 * @param id
	 * @return
	 * @author dongyibin
	 * @date 2017-9-12 下午11:51:57
	 */
	@RequestMapping("/get/{id}")
	@ResponseBody
	public ResultDto get(@PathVariable int id) {
		ResultDto rtDto = new ResultDto();
		rtDto.setData(dayReportService.get(id));
		return rtDto;
	}
}
